home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / doc / widget3.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  71 lines

  1. ; This program is used as an example in the "Widgets"
  2. ; chapter of the _Using IDL_ manual.
  3. ;
  4. PRO widget3_event, ev
  5.  
  6. ;We need to save the value of the seed variable for the random number
  7. ;generator between calls to the event-handling routine. We do this
  8. ;using a COMMON block.
  9.  
  10. COMMON wid3, seed    
  11.  
  12. ;Retrieve the widget ID of the draw widget and make it the current
  13. ;IDL graphics window:
  14.  
  15. WIDGET_CONTROL, ev.top, GET_UVALUE=drawID
  16. WSET, drawID
  17.  
  18. ;Check the type of event structure returned. If it is a timer event,
  19. ;change the color table index to a random number between 0 and 40:
  20.  
  21. IF (TAG_NAMES(ev, /STRUCTURE_NAME) EQ 'WIDGET_TIMER') THEN BEGIN
  22.    table = FIX(RANDOMU(seed)*41)
  23.    LOADCT, table
  24.    WIDGET_CONTROL, ev.id, TIMER=3.0
  25. ENDIF
  26.  
  27. ;If the event is a droplist event, change the type of plot displayed
  28. ;in the draw widget: 
  29.  
  30. IF (TAG_NAMES(ev, /STRUCTURE_NAME) EQ 'WIDGET_DROPLIST') THEN BEGIN
  31. CASE ev.index OF
  32. 0: PLOT, DIST(150)
  33. 1: SURFACE, DIST(150)
  34. 2: SHADE_SURF, DIST(150)
  35. 3: WIDGET_CONTROL, ev.top, /DESTROY
  36. ENDCASE
  37. ENDIF
  38.  
  39. END
  40.  
  41. PRO widget3
  42.  
  43. ;Create a base widget containing a draw widget and a droplist menu.
  44.  
  45. select = ['Plot', 'Surface', 'Shaded Surface', 'Done']
  46. base = WIDGET_BASE(/COLUMN)
  47. draw = WIDGET_DRAW(base, XSIZE=150, YSIZE=150)
  48. dlist = WIDGET_DROPLIST(base, VALUE=select)
  49.  
  50. ;Realize the widget hierarchy, then retrieve the widget ID of the
  51. ;draw widget and store it in the user value of the base widget.
  52. ;Finally, set the timer value of the draw widget.
  53.  
  54. WIDGET_CONTROL, base, /REALIZE
  55. WIDGET_CONTROL, draw, GET_VALUE=drawID
  56. WIDGET_CONTROL, base, SET_UVALUE=drawID
  57. WIDGET_CONTROL, draw, TIMER=0.0
  58.  
  59. ;Set the droplist to display 'Shaded Surface' and place a shaded
  60. ;surface in the draw widget:
  61.  
  62. WIDGET_CONTROL, dlist, SET_DROPLIST_SELECT=2
  63. wset, drawID
  64. SHADE_SURF, DIST(150)
  65.  
  66. ;Register the widget with the XMANAGER:
  67.  
  68. XMANAGER, 'widget3', base
  69.  
  70. END
  71.